﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Customer_Profile.Admin
{
    public partial class MenuAdd : System.Web.UI.Page
    {
        protected static int MenuId;
        protected static int lvl;

        protected void Page_Load(object sender, EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                    MenuId = Convert.ToInt32(Request.QueryString["ID"].ToString());
                else
                {
                    KVB.Common.JavaScript.ViewMsgGoUrl("MenuManage.aspx", "你必须选择");
                }

            }
        }

        protected void ibtnAdd_ServerClick(object sender, EventArgs e)
        {
            string name = txtName.Value;
            string mark = txtRemark.Value;
            string menuUrl = txtUrl.Value;
            string orderid = txtOrderid.Value;
            string use = drpUsed.SelectedValue;
            string helpDoc = txtHelp.Value;
            string helpUse = drpHelpUse.SelectedValue;
            string openmode = drpOpen.SelectedValue;

            MenuInfoEntity MenuE = new MenuInfoEntity();
            MenuE.MenuName = name;
            MenuE.Mark = mark;
            MenuE.Url = menuUrl;
            MenuE.Orderid = orderid;
            MenuE.Used = use;
            MenuE.HelpUrl = helpDoc;
            MenuE.HelpYn = helpUse;
            MenuE.OpenMode = openmode;


            Hashtable htMenuInfo = new Hashtable();


            //			cjMenuDAO MenuAdd = new cjMenuDAO();
            if (MenuId == -1)
            {
                lvl = 0;
                MenuE.ParentId = 0;
            }
            else
            {
                lvl = MenuDao.getLvl(MenuId);
                MenuE.ParentId = MenuId;
            }
            try
            {
                bool isSucess;
                if (MenuId == -1)
                {
                    MenuE.Lvl = 0;
                    htMenuInfo.Add("MenuInfo", MenuE);
                    isSucess = MenuDao.AddMenu(htMenuInfo);
                }
                else
                {
                    MenuE.Lvl = lvl + 1;
                    htMenuInfo.Add("MenuInfo", MenuE);
                    isSucess = MenuDao.AddMenu(htMenuInfo);
                }
                if (isSucess == true)
                {
                    Response.Write("<script language=javascript>alert('添加成功!');</script>");

                    //记录用户操作日志
                    //CVOC.Comm.WriteSystemLog(Session["SS_USER_ID"].ToString(), Utility.ReplaceChar(Utility.ReplaceQuote(Request["menu_idx"].ToString()), true), "02", Page.Request.UserHostAddress, Page.Request.Path, "新增菜单操作，菜单名称为：" + txtName.Value);

                }
            }
            catch
            {
                Response.Write("<script language=javascript>alert('出现数据库操作异常，没有添加成功!');</script>");
            }
        }

        protected void ibtnBack_ServerClick(object sender, EventArgs e)
        {
            //Response.Redirect("MenuManage.aspx?menu_idx=" + Utility.ReplaceChar(Utility.ReplaceQuote(Request["menu_idx"].ToString()), true));
            Response.Redirect("MenuManage.aspx", true);
        }
    }
}
